<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.name"
        placeholder="渠道名称"
        style="width: 200px; margin-right: 20px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        :loading="downloadLoading"
        @click="handleFilter"
      >
        查询
      </el-button>
      <el-button class="filter-item" style="float: right" type="primary" icon="el-icon-edit" @click="handleCreate">
        创建渠道
      </el-button>
    </div>

    <el-table :data="list" stripe style="width: 1000px" border>
      <el-table-column prop="nickname" label="渠道名称" width="300" align="center">
        <template slot-scope="{ row }">
          {{ row.nickname || "-" }}
        </template>
      </el-table-column>
      <el-table-column prop="adminname" label="上级渠道" width="200" align="center">
        <template slot-scope="{ row }">
          {{ row.adminname || "-" }}
        </template>
      </el-table-column>
      <el-table-column prop="add_time" label="添加时间" align="center" />
      <el-table-column fixed="right" label="操作" width="200" align="center">
        <template slot-scope="scope" align="center">
          <el-button type="text" size="small" @click="handleEditing(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  parseTime
} from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {
  encryption2
} from '@/api/index'
export default {
  name: 'ComplexTable',
  components: {
    Pagination
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        name: '',
        type: undefined
      },
      total: 0,
      list: [],
      downloadLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 渠道列表
    getList() {
      this.downloadLoading = true
      const arys = {
        name: this.listQuery.name,
        pageNo: this.listQuery.page,
        pageSize: this.listQuery.limit
      }
      const url = '/market/index'
      encryption2(arys, url).then((res) => {
        if (res.data.status === 0) {
          this.list = res.data.result.all_list
          this.total = res.data.result.count
        } else {
          this.$message.error(res.data.text)
        }
        this.downloadLoading = false
      })
    },
    handleFilter() {
      this.getList()
    },
    handleCreate() {
      this.$router.push({
        path: '/Channellist/CreateChannels',
        name: 'CreateChannels'
      })
    },
    handleEditing(row) {
      this.$router.push({
        path: '/Channellist/EditingChannel',
        name: 'EditingChannel',
        params: {
          Code: row
        }
      })
    }
  }
}
</script>
<style scoped>
  .filter-container .filter-item {
    margin-bottom: 0;
  }

  .el-table--border {
    border-right: 1px solid #dfe6ec;
  }

  .filter-container {
    width: 1000px;
  }
</style>
